package tests

import (
	"testing"

	"gitcode.com/deyiyangyang/showen-lang/evl"
	"gitcode.com/deyiyangyang/showen-lang/lex"
	"gitcode.com/deyiyangyang/showen-lang/prs"
	"gitcode.com/deyiyangyang/showen-lang/typ"
)

// EvaluateExpression is a helper function to parse and evaluate expressions
func EvaluateExpression(t *testing.T, input string, env *typ.Environment) string {
	// Create tokenizer
	tokenizer := lex.NewTokenizer(input)

	// Create parser
	parser, err := prs.NewParser(tokenizer)
	if err != nil {
		t.Fatalf("Failed to create parser: %v", err)
	}

	// Parse expression
	expr, err := parser.Parse()
	if err != nil {
		t.Fatalf("Failed to parse expression: %v", err)
	}

	// Evaluate expression
	result := evl.Eval(expr, env)

	// Return string representation of result
	return result.String()
}